import * as types from '../constants/actionTypes';
import api from '../services/api';
import {
    AsyncStorage
} from 'react-native';

function order_getorder(id){

    return async (dispatch)=>{
        let detail = await api.post('/order/detail',{id});

        dispatch({type:types.ORDER_DETAIL,
                  order_detail:detail});
    };
}

function order_sendaddress(address, location){
    return async (dispatch)=>{
        dispatch({type:types.SEND_ADDRESS,
                  send_address:address, send_location: location});
    };
}

function order_receiveaddress(address, location){
    return async (dispatch)=>{
        dispatch({type:types.RECEIVE_ADDRESS,
                  receive_address:address, receive_location: location});
    };
}

function order_buy_sendaddress(address, location){
    return async (dispatch)=>{
        dispatch({type:types.BUY_SEND_ADDRESS,
                  buy_send_address:address, buy_send_location: location});
    };
}

function order_buy_receiveaddress(address, location){
    return async (dispatch)=>{
        dispatch({type:types.BUY_RECEIVE_ADDRESS,
                  buy_receive_address:address, buy_receive_location: location});
    };
}


function order_clearaddress(){
    return async (dispatch)=>{
        dispatch({type:types.SEND_ADDRESS,
                  send_address:'',location:''});
        dispatch({type:types.RECEIVE_ADDRESS,
                  receive_address:'',location:''});

    };
}

function order_clearbuyaddress(){
    return async (dispatch)=>{

        dispatch({type:types.BUY_SEND_ADDRESS,
                buy_send_address:'',location:''});
        dispatch({type:types.BUY_RECEIVE_ADDRESS,
                buy_receive_address:'',location:''});
    };
}

function order_done_obj_price(str){
    return async (dispatch)=>{
        dispatch({type:types.DONE_OBJ_PRICE,
                  done_obj_price:str});
    };
}

module.exports = {
    order_getorder,
    order_sendaddress,
    order_receiveaddress,
    order_buy_sendaddress,
    order_buy_receiveaddress,
    order_clearaddress,
    order_clearbuyaddress,
    order_done_obj_price
};
